﻿Public Class clsNhanVien

    Public TenNV As String
    Public Quyen As String ''''
    Public MaNV As String
    Public Sub New()
        TenNV = ""
    End Sub
    Public Function DangNhap(ByVal MaNV As String, ByVal MatKhau As String)
        MaNV = escapeString(MaNV)
        Dim dt As DataTable = db.QueryTable("select * from nhanvien where MaNV='" & MaNV & "'")
        If dt.Rows.Count = 1 Then
            If dt.Rows(0)("MatKhau") = MatKhau Then
                MaNV = dt.Rows(0)("MaNV")
                TenNV = dt.Rows(0)("TenNV")
                Quyen = dt.Rows(0)("Quyen") 'sau khi dang nhap e se lay dc quyen dung ko
                Return True
            End If
        End If
        Return False
    End Function
    Public Shared Function DsNhanVien() As DataTable
        Return db.QueryTable("select * from NhanVien")
    End Function
    Public Function DaDangNhap() As Boolean
        Return Not TenNV = ""
    End Function
    Public Function DoiMatKhau(ByVal matkhaumoi As String) As Boolean
        matkhaumoi = escapeString(matkhaumoi)
        Return db.Query("update NhanVien set MatKhau='" & matkhaumoi & "' where MaNV='" & MaNV & "'")
    End Function
    Public Shared Function ThemNV(ByVal MaNV1 As String, ByVal TenNV1 As String, ByVal DiaChi1 As String, ByVal DienThoai1 As String, ByVal Quyen1 As String, ByVal MatKhau1 As String, ByVal ChucVu1 As String) As Boolean
        Return db.Query("Insert into NhanVien values('" & MaNV1 & "',N'" & TenNV1 & "',N'" & DiaChi1 & "','" & DienThoai1 & "',N'" & Quyen1 & "','" & MatKhau1 & "',N'" & ChucVu1 & "')")
    End Function
    Public Shared Function Xoa(ByVal MaNV1 As String) As Boolean
        Return db.Query("Delete from NhanVien where MaNV='" & MaNV1 & "'")
   
    End Function
    Public Shared Function Sua(ByVal MaNV1 As String, ByVal TenNV1 As String, ByVal DiaChi1 As String, ByVal DienThoai1 As String, ByVal Quyen1 As String, ByVal MatKhau1 As String, ByVal ChucVu1 As String) As Boolean
        Return db.Query("Update NhanVien set TenNV=N'" & TenNV1 & "',DiaChi=N'" & DiaChi1 & "',DienThoai='" & DienThoai1 & "',Quyen=N'" & Quyen1 & "',MatKhau='" & MatKhau1 & "',ChucVu=N'" & ChucVu1 & "'where MaNV ='" & MaNV1 & "'")
    End Function
    Public Shared Function TimKiem(ByVal TuKhoa As String) As DataTable
        Return db.QueryTable("Select * from NhanVien where MaNV like '%" & TuKhoa & "%'or TenNV like N'%" & TuKhoa & "%'or DiaChi like N'%" & TuKhoa & "%'or DienThoai like'%" & TuKhoa & "%'or Quyen like N'%" & TuKhoa & "%'or MatKhau like'%" & TuKhoa & "%'or ChucVu like N'%" & TuKhoa & "%' ")

    End Function
    Public Shared Function PhanLoai(ByVal quyen As String) As DataTable
        Return db.QueryTable("Select * from NhanVien where Quyen=N'" & quyen & "' ")
    End Function
    Public Shared Function ThongTinNV(ByVal MaNV As String) As DataTable
        Return db.QueryTable("Select * from NhanVien where MaNV='" & MaNV & "' ")
    End Function
    'cai nay don gian lam , hehe
End Class
